package com.fengshang.wedding.domain.service.internal;

import java.util.Collection;

import org.springframework.transaction.annotation.Transactional;

import com.fengshang.wedding.domain.model.internal.UserEntity;
/**
 * 
 *@author gembin@gmail.com
 * 
 */
@Transactional/*(readOnly = true)*/
public class UserPersistenceService extends AbstractPersistenceService<UserEntity> implements IUserPersistenceService{
     
	/*
	 * (non-Javadoc)
	 * @see com.fengshang.wedding.domain.service.internal.IUserPersistenceService#findUserById(int)
	 */
	public UserEntity findUserById(int id) {
		return findById(UserEntity.class, id);
	}
	
	/*
	 * (non-Javadoc)
	 * @see com.fengshang.wedding.domain.service.internal.IUserPersistenceService#findUserByName(java.lang.String)
	 */
	public UserEntity findUserByName(String name) {
		return findBy("name", name);
	}
	/*
	 * (non-Javadoc)
	 * @see com.fengshang.wedding.domain.service.internal.IUserPersistenceService#getTotalPages()
	 */
	public int getTotalPages(){
		return getEntityTotalPages();
	}
	/*
	 * (non-Javadoc)
	 * @see com.fengshang.wedding.domain.service.internal.IUserPersistenceService#getTotalPages(int)
	 */
	public int getTotalPages(int pageSize){
		return getEntityTotalPages(pageSize);
	}
	
	/*
	 * (non-Javadoc)
	 * @see com.fengshang.wedding.domain.service.internal.IUserPersistenceService#findUserByPagination(java.lang.String, int, int)
	 */
	public Collection<UserEntity> findUserByPagination(String query,int pageSize,
			int currentPage) {
		return findByPagination(false,query, pageSize, currentPage);
	}
	/*
	 * (non-Javadoc)
	 * @see com.fengshang.wedding.domain.service.internal.IUserPersistenceService#removeUser(com.fengshang.wedding.domain.model.internal.UserEntity)
	 */
	public void removeUser(UserEntity user) {
		 getEntityManager().remove(user);;
	}
	/*
	 * (non-Javadoc)
	 * @see com.fengshang.wedding.domain.service.internal.IUserPersistenceService#removeUser(int)
	 */
	public void removeUser(int id) {
		remove(UserEntity.class, id);
	}
	/*
	 * (non-Javadoc)
	 * @see com.fengshang.wedding.domain.service.internal.IUserPersistenceService#createUser(com.fengshang.wedding.domain.model.internal.UserEntity)
	 */
	public void createUser(UserEntity user) {
		  save(user);
	}
	/*
	 * (non-Javadoc)
	 * @see com.fengshang.wedding.domain.service.internal.IUserPersistenceService#updateUser(com.fengshang.wedding.domain.model.internal.UserEntity)
	 */
	public UserEntity updateUser(UserEntity user) {
		return update(user);
	}

	public String entityName() {
		return USER_ENTITY_NAME;
	}
	 
}
